import unittest
from Page.Page import Page
from Page.Page2 import Page2
from Page.Page3 import Page3
from selenium import webdriver
from time import sleep
from ddt import ddt, file_data
from selenium.webdriver.common.by import By


@ddt
class TestCase(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
        print('开始')

    def tearDown(self):
        sleep(3)
        self.driver.quit()
        print('结束')

    @file_data('E:\Django\DjangoProject\hzy_po\yaml.yaml')
    def test_01(self, name, pwd, exp):
        po = Page(self.driver)
        po.open_url('http://localhost:8080/')
        po.cebian()
        po.login()
        po.user(name)
        po.pwd(pwd)
        po.loginbtn()
        po.queding()
        sleep(3)
        # 断言
        a = self.driver.switch_to.alert
        b = a.text
        self.assertEqual(exp, b)


    def test_02(self):
        po = Page2(self.driver)
        po.open_url('http://localhost:8080/')
        sleep(2)
        # self.cebian()
        po.login()
        sleep(2)
        po.user()
        sleep(2)
        po.pwd()
        sleep(2)
        po.loginbtn()
        sleep(2)
        po.queding()
        sleep(2)
        po.sousuo()
        sleep(2)
        po.dianji()
        sleep(2)
        # 断言
        dy1 = self.driver.find_element(By.XPATH,
                                       '/html/body/div[1]/div/section/section/main/div[1]/div[1]/div[1]/div[3]/div/div[1]/div/table/tbody/tr/td[3]/div').text
        self.assertEqual('森林',dy1)
        print(dy1)

    def test_03(self):
        po = Page3(self.driver)
        po.open_url('http://localhost:8080/')
        sleep(2)
        # self.cebian()
        po.login()
        sleep(2)
        po.user()
        sleep(2)
        po.pwd()
        sleep(2)
        po.loginbtn()
        sleep(2)
        po.queding()
        sleep(2)
        po.shuaxin()
        sleep(2)
        #断言
        dy3 = self.driver.find_element(By.XPATH,'/html/body/div[1]/div/section/section/main/div[1]/form/div/div[5]/button/span').text
        self.assertEqual('刷新',dy3)
        print(dy3)


if __name__ == '__main__':
    unittest.main()
